package com.hjm.project.agentInfo.beautifulRecord.service.impl;

import java.util.List;

import com.hjm.common.utils.DateUtils;
import com.hjm.common.utils.LogUtils;
import com.hjm.common.utils.security.ShiroUtils;
import com.hjm.project.agentInfo.agentInfo.domain.AgentInfo;
import com.hjm.project.agentInfo.agentInfo.service.IAgentInfoService;
import com.hjm.project.agentInfo.beautifulRecord.beautifulRecord.domain.BeautifulRecord;
import com.hjm.project.agentInfo.beautifulRecord.mapper.BeautifulRecordMapper;
import com.hjm.project.agentInfo.beautifulRecord.service.IBeautifulRecordService;
import org.springframework.stereotype.Service;
import com.hjm.common.utils.text.Convert;

import javax.annotation.Resource;

/**
 * 靓号变更记录Service业务层处理
 * 
 * @author maker-platform
 * @date 2021-03-01
 */
@Service
public class BeautifulRecordServiceImpl implements IBeautifulRecordService
{
    @Resource
    private BeautifulRecordMapper beautifulRecordMapper;
    @Resource
    private IAgentInfoService agentInfoService;

    /**
     * 查询靓号变更记录
     * 
     * @param id 靓号变更记录ID
     * @return 靓号变更记录
     */
    @Override
    public BeautifulRecord selectBeautifulRecordById(Integer id)
    {
        return beautifulRecordMapper.selectBeautifulRecordById(id);
    }

    /**
     * 查询靓号变更记录列表
     * 
     * @param beautifulRecord 靓号变更记录
     * @return 靓号变更记录
     */
    @Override
    public List<BeautifulRecord> selectBeautifulRecordList(BeautifulRecord beautifulRecord)
    {
        return beautifulRecordMapper.selectBeautifulRecordList(beautifulRecord);
    }

    /**
     * 新增靓号变更记录
     * 
     * @param beautifulRecord 靓号变更记录
     * @return 结果
     */
    @Override
    public int insertBeautifulRecord(BeautifulRecord beautifulRecord)
    {
        return beautifulRecordMapper.insertBeautifulRecord(beautifulRecord);
    }
    /**
     * 异步新增靓号变更记录
     *
     * @param agentInfo 被修改的代理原生数据
     * @param updateAgentInfo 要修改的数据
     * @return 结果
     */
    @Override
    public Integer asyncInsertBeautifulRecord(AgentInfo agentInfo,AgentInfo updateAgentInfo) {
        LogUtils.logInfo("开始变更记录:" + agentInfo.getAgentNum() + "[ " + agentInfo.getAgentNum()  +" ]");
        BeautifulRecord beautifulRecord = new BeautifulRecord();
        beautifulRecord.setAfterBeautifulName(updateAgentInfo.getBeautifulName());
        beautifulRecord.setAfterBeautifulNum(updateAgentInfo.getBeautiful());
        beautifulRecord.setBeforBeautifulName(agentInfo.getBeautifulName());
        beautifulRecord.setBeforeBeautifulNum(agentInfo.getBeautiful());
        beautifulRecord.setCreateMan(ShiroUtils.getSysUser().getLoginName());
        beautifulRecord.setCreateDate(DateUtils.getTime());
        beautifulRecord.setCreateAgentName(ShiroUtils.getSysUser().getLoginName()); //先存登录名称
        beautifulRecord.setCreateAgentNum(ShiroUtils.getSysUser().getObjNo());
        beautifulRecord.setUpdateAgentNum(agentInfo.getAgentNum());
        beautifulRecord.setUpdateAgentName(agentInfo.getAgentName());
        int i = beautifulRecordMapper.insertBeautifulRecord(beautifulRecord);
        String result = i > 0 ? "成功" : "失败";
        LogUtils.logInfo("变更结束:" + agentInfo.getAgentNum() + "[ " + result + "::" + agentInfo.getAgentNum()  +" ]");
        return i;
    }

    /**
     * 修改靓号变更记录
     * 
     * @param beautifulRecord 靓号变更记录
     * @return 结果
     */
    @Override
    public int updateBeautifulRecord(BeautifulRecord beautifulRecord)
    {
        return beautifulRecordMapper.updateBeautifulRecord(beautifulRecord);
    }

    /**
     * 删除靓号变更记录对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteBeautifulRecordByIds(String ids)
    {
        return beautifulRecordMapper.deleteBeautifulRecordByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除靓号变更记录信息
     * 
     * @param id 靓号变更记录ID
     * @return 结果
     */
    @Override
    public int deleteBeautifulRecordById(Integer id)
    {
        return beautifulRecordMapper.deleteBeautifulRecordById(id);
    }
}
